from paddleocr import PaddleOCR
from time import time
from time import sleep
import redis


class OCR():
    def __init__(self, redis_pool) -> None:
        self.ocr = PaddleOCR(use_angle_cls=False, lang='ch', show_log='INFO')
        self.redis_pool = redis_pool
        self.redis_conn = redis.Redis(connection_pool=self.redis_pool)
        
    def get_conn(self):
        self.redis_conn = redis.Redis(connection_pool=self.redis_pool)

    def ocrrun(self):
        while(True):
            if not self.redis_conn:
                self.get_conn()
            img_path = self.redis_conn.lpop('imgpath')
            print(img_path)
            # img_path = 'shot_image/001122_1669271848.5451534.png'
            if not img_path:
                sleep(1)
                continue
            result = self.ocr.ocr(img_path, cls=False)
            for res in result:
                print(res[1][0])
            break

            
